<template>
  <div class="container">
    <el-form ref="form" :model="filterForm">
      <el-form-item>
        <el-button class="filter-item" style="float: right;" @click="handleCreate" type="primary" icon="el-icon-plus">新增机构用户</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="userList" border fit el-tabl stripe
      style="width: 100%;">
      <el-table-column prop="id" align="center" label="编号" width="0" v-if="false">
      </el-table-column>
      <el-table-column prop="department" align="center" label="政府机构名称" width="260">
      </el-table-column>
      <el-table-column prop="name" min-width="150px" label="登录账号">
      </el-table-column>
      <el-table-column prop="swoption" min-width="100px" label="对应税务机构">
      </el-table-column>
      <el-table-column width="150px" label="操作">
        <template slot-scope="scope">
          <el-button size="small" type="primary" plain>删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination background
        layout="total, prev, pager, next"
        :total="count"
        :page-size="size"
        :current-page="page"
        @current-change="handleCurrentChange">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { getuserList } from '@/api/register';

export default {
  name: 'Orderlist',
  data() {
    return {
      filterForm: {
        name: ''
      },
      userList: [],
      count: 0,
      pageCurrent: 1,
      size: 20
    };
  },
  created() {
    this.getuserList('1');
  },
  methods: {
    // 当前的页码，改变时会触发
    handleCurrentChange: function(currentPage) {
      this.getuserList(currentPage);
    },
    handleCreate() {
      this.$router.push({ path: '/user/usercreate' });
    },
    //初始化数据
    getuserList(page) {
      let that = this;
      that.loading = true;
      getuserList(page)
        .then(data => {
          that.loading = false;
          var myData = data.data;

          if (myData.length <= 0) {
            var lenth = this.userList.length;
            that.userList.splice(0, lenth);
          } else {
            lenth = this.userList.length;
            that.userList.splice(0, lenth);
            //加入数据内容
            for (let i of myData) {
              var map = {
                id: i.id,
                department: i.department,
                name: i.username,
                cont: i.contname
              };
              that.userList.push(map);
            }
            var pageData = data.page;
            that.total = pageData.resultCount;
            that.count = pageData.pageCount;
            that.pageCurrent = pageData.pageCurrent;
            that.size = pageData.pageLimit;
          }
        })
        .catch(function(error) {
          console.log(error);
          that.loading = false;
        });
    }
  }
};
</script>
<style>
</style>
